package com.changfang.gold_man.service.Imp;

import com.changfang.gold_man.entity.Courier;
import com.changfang.gold_man.mapper.CourierMapper;
import com.changfang.gold_man.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.bind.DatatypeConverter;
import java.util.List;
import java.util.Map;

@Service
public class CourierServiceImpl implements CourierService {
    @Autowired
    private CourierMapper courierMapper;
    //查询所有快递
    @Override
    public List<Courier> findAll() {
        try {
            List<Courier> courierList = courierMapper.findAll();

            return courierList;
        }catch (Exception e){
            return null;
        }

    }
    //修改快递状态
    @Override
    public String updateStatus(String courier_id, String courier_status) {
        try {
            courierMapper.updateStatus(courier_id,courier_status);
            return "SUCCESS";
        }catch (Exception e){
            return "ERROR";
        }

    }
    //删除快递
    @Override
    public String delete(String courier_id) {
        try {
            courierMapper.delete(courier_id);
            return "SUCCESS";
        }catch (Exception e){
            return "ERROR";
        }
    }
//导入快递记录
    @Override
    public String addCourier(Map<String, String> courierInfo, String url) {
        try {
            String courier_id = courierInfo.get("courier_id");
            String courier_title = courierInfo.get("courier_title");
            String courier_address = courierInfo.get("courier_address");
            String courier_code = courierInfo.get("courier_code");
            String user_id = courierInfo.get("user_id");
            String courier_status = "1";
            courierMapper.addCourier(courier_id,courier_title,courier_address,courier_code,url,courier_status,user_id);
            return "SUCCESS";
        }catch (Exception e){
            return "ERROR";
        }

    }
    //收件人查找快递
    @Override
    public List<Courier> findUid(String user_id) {
        try {
            List<Courier> courierList = courierMapper.findUid(user_id);
            return courierList;
        }catch (Exception e){
            return null;
        }

    }


}
